package com.jinlejia.erp.ui.house;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.jinlejia.erp.R;
import com.jinlejia.erp.adapter.ViewPagerAdapter;
import com.jinlejia.erp.databinding.ActivityApplyDictBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * @author SongJiaTai
 * @description:申请房源字典
 * @date :2019/6/12 16:13
 */
public class ApplyDictActivity extends AppCompatActivity{
    private ActivityApplyDictBinding applyDictBinding;
    // 填充到ViewPager中的Fragment
    private List<Fragment> mFragments;
    //Tab选项卡的文字
    private String mTitleArray[] = new String[1];
    private ViewPagerAdapter viewPagerAdapter;
    private int ishouse;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        applyDictBinding = DataBindingUtil.setContentView(this, R.layout.activity_apply_dict);
        applyDictBinding.setClickmager(this);
        ishouse  = getIntent().getIntExtra("ishouse", 0);
        mFragments = new ArrayList<>();
        initdata();

        viewPagerAdapter = new ViewPagerAdapter(this.getSupportFragmentManager(), mTitleArray, mFragments);
        applyDictBinding.viewPager.setAdapter(viewPagerAdapter);

        // 设置Tablayout的Tab显示ViewPager的适配器中的getPageTitle函数获取到的标题
        applyDictBinding.idTableLayout.setTabsFromPagerAdapter(viewPagerAdapter);
        applyDictBinding.idTableLayout.post(new Runnable() {
            @Override
            public void run() {
                // 将TabLayout和ViewPager进行关联，让两者联动起来
                applyDictBinding.idTableLayout.setupWithViewPager( applyDictBinding.viewPager);
            }
        });


    }

    private void initdata() {
        if (ishouse==0){
            mTitleArray[0] = "房间";

            mFragments.add(new ApplyHouseFragment());
        }else{
            mTitleArray[0] = "楼盘和房间";
            mFragments.add(new ApplyPropertiesFragment());
        }
    }

    //返回图标点击事件
    public void bcakOnclick(View view) {
        finish();
    }


}
